/**********************************************************************************
***
***    Screencasting Teaching System C++ Library
***    Copyright (C) 2011  Jiri Novak <jiri.novak@petriny.net>
***                        Wadi Jalil Maluf <wadijm@gmail.com>
***
***    This file is part of the Screencasting Teaching System C++ Library.
***
***    This library is free software; you can redistribute it and/or modify
***    it under the terms of the GNU General Public License as published by
***   the Free Software Foundation; either version 3 of the License, or
***    (at your option) any later version.
***
***    This library is distributed in the hope that it will be useful,
***    but WITHOUT ANY WARRANTY; without even the implied warranty of
***    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
***   GNU General Public License for more details.
***
***    You should have received a copy of the GNU General Public License
***    along with this library; if not, write to the Free Software
***    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
***
*********************************************************************************/

#ifndef SCPERSISTENCESERVICE_H_
#define SCPERSISTENCESERVICE_H_
#include "../common/model/lesson.h"
#include "../common/comm/blockingqueue.h"
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
/**
 * Clase utilizada para persistir datos de una leccion(video+audio+chat)
 */
class ScPersistenceService
{
public:
  ScPersistenceService(Lesson& lesson,std::string path);
  virtual
  ~ScPersistenceService();
  /**
   * Persiste los datos del mensaje de chat en archivo binario.
   * @param data: datos a persistir
   */
  void persistChatMessage(char* data,int size);
  /**
     * Persiste los datos del mensaje de chat en archivo binario.
     * @param data: datos a persistir
     */
  void persistScreenCastData(char* data,int size);
  /**
     *Envia los datos de la leccion con la cual fue instanciado .
     * @param data: cola donde poner los datos para que sean enviados al usuario
     * que requirio el replay del screencast
     */
  void sendSavedScreencast(BlockingQueue& queue);
  void openForWriting();
  void openForReading();
  /**
   * @return Verdadero en caso de que exista el archivo de persitencia para la lección instanciada.
   */
  bool isAvailable();

private:
std::fstream *chatStream;
std::fstream *scStream;
std::string savePath;
void sendStreamData(std::fstream* stream,BlockingQueue& queue);
};

#endif /* SCPERSISTENCESERVICE_H_ */
